module executor.friend.client.DeleteFriendExecutor;

import msgtrans;
import message.Constants;
import cache.UserStatusManager;
import hunt.logging;
import google.protobuf;
import message.MsgDefine;
import cache.ChatIdMap;
import client.GateServerClient;
import std.array;
import std.conv : to;

@TransportClient(LogicClientName)
class DeleteFriendExecutor : AbstractExecutor!(DeleteFriendExecutor){

    @MessageId(MESSAGE.CMD_DELETE_FRIEND_REQ)
    void deleteFriend(TransportContext ctx, MessageBuffer buffer)
    {
      auto deleteFriend = new DeleteContactREQ;
      buffer.data.fromProtobuf!DeleteContactREQ( deleteFriend);

      if (UserStatusManager.getInstance().getUserStatus(deleteFriend.userId)) //在线
      {
        auto deleteFriendRes  = new DeleteContactRES;
        deleteFriendRes.userId = deleteFriend.userId;
        deleteFriendRes.friendId = deleteFriend.friendId;
        deleteFriendRes.succeeded = true;
        TransportSession[ulong] contexts = GateServerClient.getInstance.getAllClient();
        foreach (TransportSession c ; contexts)
        {
          c.send( new MessageBuffer( MESSAGE.CMD_DELETE_FRIEND_RES,deleteFriendRes.toProtobuf.array));
        }
      }
    }
}

